//
//  XHRSubTagCell.m
//  BuDeJie
//
//  Created by haoran on 16/4/5.
//  Copyright © 2016年 xuhaoran. All rights reserved.
//

#import "XHRSubTagCell.h"
#import "XHRSubTagItem.h"
#import <UIImageView+WebCache.h>

@interface XHRSubTagCell()

@property (weak, nonatomic) IBOutlet UIImageView *iconView;

@property (weak, nonatomic) IBOutlet UILabel *nameView;

@property (weak, nonatomic) IBOutlet UILabel *numView;

@end

@implementation XHRSubTagCell

/*
 界面细节:
 1.头像 圆 1.修改控件的圆角半径 2.裁剪图片生成一张新的圆角图片,图形上下文
 2.数字
 */
/*
 iOS9,帧数不会下降,苹果修复这个问题
 iOS8之前 还是有问题
 */

#pragma mark ---- 重写模型set方法
-(void)setItem:(XHRSubTagItem *)item{
    
    _item = item;
 
    // 占位头像
    UIImage *placeholder = [UIImage xhr_circleImageNamed:@"defaultUserIcon"];
    //图标
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:item.image_list] placeholderImage:placeholder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        
        if (image == nil) return ;
        
        //返回一个未经渲染的图片
        self.iconView.image = [image circleImage];
        
    }];
    
    //名称
    self.nameView.text = item.theme_name;
    
    //订阅数
    NSString * numstr = [NSString stringWithFormat:@"%@万人已经订阅",item.sub_number];
    
    NSInteger num = numstr.intValue ;
    
    if (num > 10000) {
        CGFloat numF = num / 10000.0;
        numstr = [NSString stringWithFormat:@"%.1f万人已订阅",numF];
        numstr = [numstr stringByReplacingOccurrencesOfString:@".0" withString:@""];
    }
    self.numView.text = numstr;


}

//从xib加载就会调用,只会调用一次 在这个方法里面设置圆角矩形
- (void)awakeFromNib {

    //设置边框圆角半径为iconView的一半
//    self.iconView.layer.cornerRadius = self.iconView.xhr_width * 0.5;
    
    //超过主层边框的部分减去
//    self.iconView.layer.masksToBounds = YES;
    
    
}

#pragma mark ---- 重写setFrame方法
-(void)setFrame:(CGRect)frame{
    
    frame.size.height -= 1;//iOS6时代就开始这么做,典型案例,新浪微博

    //给frame赋值
    [super setFrame:frame];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
